package com.yunhe.portal.controller;
import com.yunhe.common.exception.ArgumentErrorException;
import com.yunhe.portal.domain.DataNoticeInfo;
import com.yunhe.portal.model.*;
import com.yunhe.portal.service.DataNoticeInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.yunhe.common.model.ResultObject;
import com.yunhe.common.model.mybatis.PageResult;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @description 公告表
 * @author misty
 * @date 2021-10-19
 */
@Api(value = "DataNoticeInfo", description = "公告表维护", tags = {"公告表维护"})
@RestController
@RequestMapping(value = "/dataNoticeInfo")
public class DataNoticeInfoController {

    @Autowired
    private DataNoticeInfoService dataNoticeInfoService;

    /**
     * 新增
     * @author misty
     * @date 2021/10/19
     **/
    @ApiOperation("新增公告表")
    @PostMapping("/createDataNoticeInfo")
    public ResponseEntity<ResultObject> createDataNoticeInfo(@RequestBody DataNoticeInfo dataNoticeInfo) throws ArgumentErrorException {
        dataNoticeInfoService.createDataNoticeInfo(dataNoticeInfo);
        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
    }

    /**
     * 刪除
     * @author misty
     * @date 2021/10/19
     **/
    @ApiOperation("根据id删除公告表")
    @DeleteMapping("/deleteDataNoticeInfo")
    public ResponseEntity<ResultObject> deleteDataNoticeInfo(@RequestParam(value = "id",required = true) int id){
        dataNoticeInfoService.deleteDataNoticeInfo(id);
        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
    }

    /**
     * 更新
     * @author misty
     * @date 2021/10/19
     **/
    @ApiOperation("更新公告表")
    @PostMapping("/updateDataNoticeInfo")
    public ResponseEntity<ResultObject> updateDataNoticeInfo(@RequestBody DataNoticeInfo dataNoticeInfo) throws ArgumentErrorException {
        dataNoticeInfoService.updateDataNoticeInfo(dataNoticeInfo);
        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
    }

    /**
     * 查询 根据主键 id 查询
     * @author misty
     * @date 2021/10/19
     **/
    @ApiOperation("根据id查询公告表")
    @GetMapping("/findDataNoticeInfoById")
    public ResponseEntity<ResultObject<DataNoticeInfo>> findDataNoticeInfoById(@RequestParam(value = "id",required = true) int id){
        return new ResponseEntity<>(new ResultObject(dataNoticeInfoService.findDataNoticeInfoById(id)),HttpStatus.OK);
    }

    @ApiOperation("web根据条件查询公告列表")
    @PostMapping("/findDataNoticeInfoByCondition")
    public ResponseEntity<ResultObject<List<DataNoticeInfoVo>>>findDataNoticeInfoByCondition(@RequestBody NoticeInfoQueryCondition noticeInfoQueryCondition) throws ArgumentErrorException {
        PageResult result = dataNoticeInfoService.findDataNoticeInfoByCondition(noticeInfoQueryCondition);
        return new ResponseEntity(new ResultObject(result),HttpStatus.OK);
    }

    @ApiOperation("设置发布状态")
    @PostMapping("/setPublishStatus")
    public ResponseEntity<ResultObject> setPublishStatus(@RequestBody PublishStatus publishStatus) throws ArgumentErrorException {
        dataNoticeInfoService.setPublishStatus(publishStatus);
        return new ResponseEntity<>(new ResultObject(),HttpStatus.OK);
    }

}